package com.liyujie.networkrequest.ui.management.serialport;

import android.os.Bundle;
import android.view.View;

import com.blankj.utilcode.util.SPUtils;
import com.liyujie.networkrequest.R;
import com.liyujie.networkrequest.databinding.ActivitySerialPortBinding;
import com.liyujie.networkrequest.listener.BeCommonCallback;
import com.liyujie.networkrequest.pop.DoorOpeningNumberSettingPopup;
import com.liyujie.networkrequest.pop.SerialPortPopup;
import com.liyujie.networkrequest.ui.BaseActivity;
import com.liyujie.networkrequest.utils.InitializeUtils;
import com.liyujie.networkrequest.views.NoDoubleClickListener;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;

public class SerialPortActivity extends BaseActivity<ActivitySerialPortBinding> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_serial_port;
    }

    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("串口管理");

    }

    @Override
    public void initData() {
        super.initData();



    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        //刷卡串口设置
        binding.QuantitySetting.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                /**
                 * 串口
                 */
                SerialPortPopup mSerialPortPopup = new SerialPortPopup(mContext,SPUtils.getInstance().getString("OpenSerialPort","/dev/ttyS4"));
                mSerialPortPopup.setBeCommonCallback(new BeCommonCallback() {
                    @Override
                    public void onBeCommonCallback(Object mObject) {
                        String SerialPortNumber = (String) mObject;
                        SPUtils.getInstance().put("OpenSerialPort",SerialPortNumber);
                        InitializeUtils.getDefaultMaker().show(SerialPortNumber + "设置成功,重新打开应用");
                    }
                });
                new XPopup
                        .Builder(mContext)
                        .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                        .autoOpenSoftInput(false)
                        .asCustom(mSerialPortPopup)
                        .show();
            }
        });
        //刷卡串口设置
        binding.SKTheDoorASerialPort.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                /**
                 * 串口
                 */
                SerialPortPopup mSerialPortPopup = new SerialPortPopup(mContext,SPUtils.getInstance().getString("CreditCardSerialPort","/dev/ttyS2"));
                mSerialPortPopup.setBeCommonCallback(new BeCommonCallback() {
                    @Override
                    public void onBeCommonCallback(Object mObject) {
                        String SerialPortNumber = (String) mObject;
                        SPUtils.getInstance().put("CreditCardSerialPort",SerialPortNumber);
                        InitializeUtils.getDefaultMaker().show(SerialPortNumber + "设置成功,重新打开应用");
                    }
                });
                new XPopup
                        .Builder(mContext)
                        .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                        .autoOpenSoftInput(false)
                        .asCustom(mSerialPortPopup)
                        .show();
            }
        });
        //开门编号设置
        binding.OpenTheDoorNumber.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                DoorOpeningNumberSettingPopup mDoorOpeningNumberSettingPopup = new DoorOpeningNumberSettingPopup(mContext);
                new XPopup
                        .Builder(mContext)
                        .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                        .autoOpenSoftInput(false)
                        .asCustom(mDoorOpeningNumberSettingPopup)
                        .show();
            }
        });
    }

}